import { reactive } from 'vue'
import { addData, updateData, getDataForm } from '@/api/base/shop'
import { getOptionList } from '@/api/base/brand'
export function useDetail(getFormValues: Function) {
  const status = reactive({
    saving: false,
    loading: false
  })

  const createOrUpdate = async () => {
    const values = getFormValues()
    if (status.saving) return false
    status.saving = true
    try {
      values?.code ? await updateData(values.code, values) : await addData(values)
      status.saving = false
      return true
    } catch (err) {
      status.saving = false
      return false
    }
  }

  const getDataById = async (userCode: any) => {
    return getDataForm(userCode)
  }

  const getBrandOptions = async () => {
    return getOptionList()
  }

  return { status, createOrUpdate, getDataById, getBrandOptions }
}
